﻿using FlowerShop.Core.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Threading.Tasks;


namespace BLL.Services
{
    public class ProductService
    {
        private readonly Model1 _context;

        public ProductService()
        {
            _context = new Model1();
        }

        public IEnumerable<Tgood> GetAllProducts()
        {
            return _context.Tgood.ToList();
        }

        public Tgood GetProductById(int id)
        {
            return _context.Tgood.FirstOrDefault(p => p.G_id == id);
        }

        public IEnumerable<Tgood> GetProductsByPriceRange(decimal min, decimal max)
        {
            return _context.Tgood.Where(p => p.G_xiaoshoujia >= min && p.G_xiaoshoujia <= max).ToList();
        }

        public IEnumerable<Tgood> SearchProducts(string keyword)
        {
            return _context.Tgood.Where(p => p.G_name.Contains(keyword)).ToList();
        }
    }
}
